import {$post} from '../util/request.js'
export default {
	namespaced:true,
	state(){
		return{
			userinfo:null,
			img:'../../static/logo.png'
		}
	},
	mutations:{
		initUserinfo(state,obj){
			state.userinfo=obj
			console.log(state.userinfo);	
		},
			
		initimg(state,url){
			console.log(url);
			state.img = url
		}
	},
		
	actions:{
			
		userLoginAct(context,info){
			console.log(info);
			$post('/1.1/login',info).then(res=>{
				console.log(res);
					
				if(res.code == 211){
				 return	uni.showToast({
						title:"用户名错误",
						icon:"none"
					})
				}
				if(res.code == 210){
				 return	uni.showToast({
						title:"密码错误",
						icon:"none"
					})
				}
				uni.showToast({
					title:"成功"	,
					icon:'none',
					success: () => {
						setTimeout(()=>{
							uni.navigateBack()
						},2000)
					}
				})
				context.commit("initUserinfo",res)
				uni.setStorage({
					key: "username",
					data: res,
					success: function (res) {
						console.log(res);
					}
				});
			
			
			})
		
		}
	}
}
